package com.ytjj.qmyx.mall.service.impl;

import com.ytjj.qmyx.mall.mapper.ProductGroupBuyInfoMapper;
import com.ytjj.qmyx.mall.model.ProductGroupBuyInfo;
import com.ytjj.qmyx.mall.model.ProductGroupBuyInfoExample;
import com.ytjj.qmyx.mall.service.YxProductGroupBuyInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class YxProductGroupBuyInfoServiceImpl implements YxProductGroupBuyInfoService {
    @Resource
    public ProductGroupBuyInfoMapper productGroupBuyInfoMapper;

    /**
     * 查下商品正在进行中的拼团配置信息
     * @param productId
     * @return
     */
    @Override
    public ProductGroupBuyInfo queryByProductId(Integer productId) {
        ProductGroupBuyInfoExample example = new ProductGroupBuyInfoExample();
        example.createCriteria().andProductIdEqualTo(productId).andStatusEqualTo((byte)1);
        List<ProductGroupBuyInfo> list = productGroupBuyInfoMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public List<ProductGroupBuyInfo> queryByProductIds(List<Integer> productIds) {
        ProductGroupBuyInfoExample example = new ProductGroupBuyInfoExample();
        example.createCriteria().andProductIdIn(productIds);
        List<ProductGroupBuyInfo> list = productGroupBuyInfoMapper.selectByExample(example);
        return list;
    }
}
